home *** CD-ROM | disk | FTP | other *** search
/ PD Collection CD 1 / PD Collection CD 1.iso / textual / pdftops / xpdf / h / XOutputDev < prev    next >
Text File  |  1996-05-23  |  5KB  |  196 lines

  1. //========================================================================
  2. //
  3. // XOutputDev.h
  4. //
  5. // Copyright 1996 Derek B. Noonburg
  6. //
  7. //========================================================================
  8.  
  9. #ifndef XOUTPUTDEV_H
  10. #define XOUTPUTDEV_H
  11.  
  12. #ifdef __GNUC__
  13. #pragma interface
  14. #endif
  15.  
  16. #include <stddef.h>
  17. #include <X11/Xlib.h>
  18. #include <X11/Xutil.h>
  19. #include "config.h"
  20. #include "OutputDev.h"
  21.  
  22. class GString;
  23. class LTKApp;
  24. class LTKWindow;
  25. class GfxColor;
  26. class GfxFont;
  27. struct RGBColor;
  28.  
  29. #define maxRGBCube 8        // max size of RGB color cube
  30.  
  31. #define numTmpPoints 256    // number of XPoints in temporary array
  32.  
  33. //------------------------------------------------------------------------
  34. // XOutputFont
  35. //------------------------------------------------------------------------
  36.  
  37. class XOutputFont {
  38. public:
  39.  
  40.   // Constructor.
  41.   XOutputFont(GfxFont *gfxFont, double m11, double m12,
  42.           double m21, double m22, Display *display1);
  43.  
  44.   // Destructor.
  45.   ~XOutputFont();
  46.  
  47.   // Does this font match the tag, size, and angle?
  48.   GBool matches(GString *tag1, double m11, double m12, double m21, double m22)
  49.     { return tag->cmp(tag1) == 0 && mat11 == m11 && mat12 == m12 &&
  50.          mat21 == m21 && mat22 == m22; }
  51.  
  52.   // Get X font.
  53.   XFontStruct *getXFont() { return xFont; }
  54.  
  55.   // Get character mapping.
  56.   Gushort mapChar(Guchar c) { return map[c]; }
  57.  
  58.   // Reverse map a character.
  59.   Guchar revMapChar(Gushort c) { return revMap[c]; }
  60.  
  61. private:
  62.  
  63.   GString *tag;
  64.   double mat11, mat12, mat21, mat22;
  65.   Display *display;
  66.   XFontStruct *xFont;
  67.   Gushort map[256];
  68.   Guchar *revMap;
  69. };
  70.  
  71. //------------------------------------------------------------------------
  72. // XOutputFontCache
  73. //------------------------------------------------------------------------
  74.  
  75. class XOutputFontCache {
  76. public:
  77.  
  78.   // Constructor.
  79.   XOutputFontCache(Display *display1);
  80.  
  81.   // Destructor.
  82.   ~XOutputFontCache();
  83.  
  84.   // Get a font.  This creates a new font if necessary.
  85.   XOutputFont *getFont(GfxFont *gfxFont, double m11, double m12,
  86.                double m21, double m22);
  87.  
  88. private:
  89.  
  90.   Display *display;        // X display pointer
  91.   XOutputFont *            // fonts in reverse-LRU order
  92.     fonts[fontCacheSize];
  93.   int numFonts;            // number of valid entries
  94. };
  95.  
  96. //------------------------------------------------------------------------
  97. // XOutputState
  98. //------------------------------------------------------------------------
  99.  
  100. struct XOutputState {
  101.   GC strokeGC;
  102.   GC fillGC;
  103.   Region clipRegion;
  104.   XOutputState *next;
  105. };
  106.  
  107. //------------------------------------------------------------------------
  108. // XOutputDev
  109. //------------------------------------------------------------------------
  110.  
  111. class XOutputDev: public OutputDev {
  112. public:
  113.  
  114.   // Constructor.
  115.   XOutputDev(LTKWindow *win1);
  116.  
  117.   // Destructor.
  118.   virtual ~XOutputDev();
  119.  
  120.   // Does this device use upside-down coordinates?
  121.   // (Upside-down means (0,0) is the top left corner of the page.)
  122.   virtual GBool upsideDown() { return gTrue; }
  123.  
  124.   // Set page size (in pixels).
  125.   virtual void setPageSize(int x, int y);
  126.  
  127.   // Reset state and clear display, to prepare for a new page.
  128.   virtual void clear();
  129.  
  130.   // Dump page contents to display.
  131.   virtual void dump();
  132.  
  133.   //----- save/restore graphics state
  134.   virtual void saveState(GfxState *state);
  135.   virtual void restoreState(GfxState *state);
  136.  
  137.   //----- update graphics state
  138.   virtual void updateAll(GfxState *state);
  139.   virtual void updateCTM(GfxState *state);
  140.   virtual void updateLineDash(GfxState *state);
  141.   virtual void updateLineJoin(GfxState *state);
  142.   virtual void updateLineCap(GfxState *state);
  143.   virtual void updateMiterLimit(GfxState *state);
  144.   virtual void updateLineWidth(GfxState *state);
  145.   virtual void updateFillColor(GfxState *state);
  146.   virtual void updateStrokeColor(GfxState *state);
  147.   virtual void updateFont(GfxState *state);
  148.  
  149.   //----- path painting
  150.   virtual void stroke(GfxState *state);
  151.   virtual void fill(GfxState *state);
  152.   virtual void eoFill(GfxState *state);
  153.  
  154.   //----- path clipping
  155.   virtual void clip(GfxState *state);
  156.   virtual void eoClip(GfxState *state);
  157.  
  158.   //----- text drawing
  159.   virtual void drawChar(GfxState *state, double x, double y, Guchar c);
  160.  
  161.   //----- image drawing
  162.   virtual void drawImageMask(GfxState *state, Stream *str,
  163.                  int width, int height, GBool invert);
  164.   virtual void drawImage(GfxState *state, Stream *str, int width,
  165.              int height, GfxColorSpace *colorSpace);
  166.  
  167. private:
  168.  
  169.   LTKWindow *win;        // window
  170.   LTKScrollingCanvas *canvas;    // drawing canvas
  171.   Display *display;        // X display pointer
  172.   int screenNum;        // X screen number
  173.   Pixmap pixmap;        // pixmap to draw into
  174.   GC paperGC;            // GC for background
  175.   GC strokeGC;            // GC with stroke color
  176.   GC fillGC;            // GC with fill color
  177.   Region clipRegion;        // clipping region
  178.   Gulong            // color cube
  179.     colors[maxRGBCube * maxRGBCube * maxRGBCube];
  180.   int numColors;        // size of color cube
  181.   XPoint            // temporary points array
  182.     tmpPoints[numTmpPoints];
  183.   GfxFont *gfxFont;        // current PDF font
  184.   XOutputFont *font;        // current font
  185.   XOutputFontCache *fontCache;    // font cache
  186.   XOutputState *save;        // stack of saved states
  187.  
  188.   void updateLineAttrs(GfxState *state, GBool updateDash);
  189.   void doFill(GfxState *state, int rule);
  190.   XPoint *pathPoints(GfxState *state, int *numPoints);
  191.   Gulong findColor(GfxColor *color);
  192.   Gulong findColor(RGBColor *x, RGBColor *err);
  193. };
  194.  
  195. #endif
  196.